using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TriUan.TriUanGame.GameComponents.Polygon
{
    class VerticesTransform
    {
        private VerticesTransform()
        {
        }

        public static VerticesTransform Instance { get; private set; }

        static VerticesTransform()
        {
            Instance = new VerticesTransform();
        }

        public List<Vector2> Transform(List<Vector2> vertices, Vector2 translate, Vector2 origin, float scale, float rotation)
        {
            List<Vector2> transformedVertices = new List<Vector2>(vertices.Count);

            Matrix transform = Matrix.Identity;
            transform *= Matrix.CreateTranslation(new Vector3(-origin, 0f));
            transform *= Matrix.CreateScale(new Vector3(scale, scale, 1f));
            transform *= Matrix.CreateRotationZ(rotation);
            transform *= Matrix.CreateTranslation(new Vector3(translate, 0f));

            foreach (Vector2 vertex in vertices)
            {
                transformedVertices.Add(Vector2.Transform(vertex, transform));
            }

            return transformedVertices;
        }
    }
}
